import java.awt.*;
import java.awt.event.MouseEvent;
import java.util.LinkedList;

public class DrawAllDoraemonPhotoAndInfo implements IEngine {


    Rectangle[] allDoraemonPhotoAndInfoCollider;

    @Override
    public void render(Graphics graphics, LinkedList<AbstractBiology> abstractBiologyLinked) {

        allDoraemonPhotoAndInfoCollider = new Rectangle[abstractBiologyLinked.size()];

        for (int i = 0; i < abstractBiologyLinked.size(); i++) {
            // System.out.println("abstractBiologyLinked");
            allDoraemonPhotoAndInfoCollider[i] = drawPhotoAndInfo(graphics, abstractBiologyLinked.get(i), i);
        }

    }

    Graphics g;

    @Override
    public void tick() {
        //render(g);
    }

    private Rectangle drawPhotoAndInfo(Graphics g, AbstractBiology tempAbstractBiology, int index) {

        this.g = g;
        g.setColor(Color.ORANGE);
        g.fill3DRect(0, Global.CELL_SIZE * index, Global.CELL_SIZE * 3, Global.CELL_SIZE, true);
        Font font = new Font("宋体", Font.BOLD, 30);
        g.setFont(font);
        g.drawImage(tempAbstractBiology.getImageFace(), 0, Global.CELL_SIZE * index, Global.CELL_SIZE, Global.CELL_SIZE, null);
        g.setColor(Color.red);
        g.drawString("姓名：" + tempAbstractBiology.getName(), 90, 30+Global.CELL_SIZE * index);
        g.drawString("HP:" + tempAbstractBiology.getHP() + "/" + tempAbstractBiology.getMaxHP(), 90, 60+Global.CELL_SIZE * index);
        return new Rectangle(0, Global.CELL_SIZE * index, Global.CELL_SIZE * 3, Global.CELL_SIZE);
    }


    public void mousePressedPhoto(MouseEvent e, LinkedList<AbstractBiology> abstractBiologyLinked) {
        for (int i = 0; i < allDoraemonPhotoAndInfoCollider.length; i++) {
            if (allDoraemonPhotoAndInfoCollider[i].contains(e.getPoint())) {
                for (int j = 0; j < abstractBiologyLinked.size(); j++) {
                    abstractBiologyLinked.get(j).setSelected(false);
                    abstractBiologyLinked.get(j).setMove(false);
                    abstractBiologyLinked.get(j).setAttack(false);
                }
                abstractBiologyLinked.get(i).setSelected(true);
            }
        }
    }

}
